/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.makimo.fuzzy.sets;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import pl.makimo.data.Record;
import pl.makimo.fuzzy.sets.memberships.ContinuousMembershipFunction;
import pl.makimo.fuzzy.sets.memberships.MembershipFunction;

/**
 *
 * @author Mateusz Papiernik
 */
public class DiscreteFuzzySet<T> extends FuzzySet<T> {
	public CrispSet<T> elements = new CrispSet<T>();
	
    public DiscreteFuzzySet(MembershipFunction membershipFunction) {
		super();
		this.membershipFunction = membershipFunction;
	}
    
    public DiscreteFuzzySet(MembershipFunction membershipFunction, CrispSet<T> elements, String column) {
		super();
		this.membershipFunction = membershipFunction;
		this.elements = elements;
		this.column = column;
	}    
	
    @Override
    public CrispSet<T> support() {    	    	
    	CrispSet<T> sup = new CrispSet<T>();
    	
    	for (T element : elements) {
    		if ((Double)this.value(element) > 0) {    			
    			sup.add(element);
    		}
    	}
    	
    	return sup;
    }
    
    @Override
    public double in() {
    	return (double)support().cardinality() / crispCardinality();
    }
    
    @Override
    public double crispCardinality() {
    	return (double)elements.cardinality();
    }
    
    @Override
    public double cardinality() {
    	return sigmaCount();
    }

    public double sigmaCount() {
    	double card = 0.0;
    	
    	for (T element : elements) {
    		card += (Double)this.value(element);
    	}
    	
    	return card;    	
    }

	@Override
	public double maxWithOne() {
		List<Double> maxElems = new ArrayList<Double>();
		maxElems.add(0.0);
		
    	for (T element : elements) {
    		if ((Double)this.value(element) == 1.0) {
    			maxElems.add((double)((Double)element));
    		}
    	}
    	
    	return Collections.max(maxElems);
	}

	@Override
	public double maxMembership() {
		List<Double> maxElems = new ArrayList<Double>();
		maxElems.add(0.0);
		
    	for (T element : this.elements) {
    		double el = (Double)element;
    		    		
    		if (el > 0.0) {    		
    			double value = (Double)this.value(element);
    			maxElems.add(value);
    		}
    	}
    	
    	return Collections.max(maxElems);
	}	
}
